﻿<%@ Page Language="C#" AutoEventWireup="true" CodeFile="SetPage.aspx.cs" Inherits="Whir_System_Module_Template_SetPage" %>

<html xmlns="http://www.w3.org/1999/xhtml">
<head runat="server">
    <title>分页标签参数设置</title>
    <link href="../../Skin/Default/Css/main.css" rel="stylesheet" type="text/css" />
    <style type="text/css">
    html {
	    overflow-x: hidden; /*隐藏水平滚动条*/
    }
    </style>
</head>
<body scroll="no" onload="setEdit();">
    <form id="form1" runat="server">
        <table width="99%" border="0" cellpadding="0" cellspacing="1" bgcolor="#DADADA">
            <tr>
                <td width="80px" height="28" align="center" class="form_tdText">ID </td>
                <td class="form_tdText">&nbsp;<asp:TextBox ID="txtID" runat="server" Width="80"></asp:TextBox>
                    <a onclick="document.getElementById('txtID').value='Info'+(Math.round(Math.random()*100));">
                        随机</a><br />
                    <span class="form_desc">[设置此项可便于在左边工具箱中的快速定位]</span></td>
            </tr>
            <tr>
                <td height="28" align="center" class="form_tdText">样式 </td>
                <td class="form_tdText">&nbsp;<asp:TextBox ID="txtClass" runat="server" Width="80"
                    Text="Page"></asp:TextBox>
                    <span class="form_desc">[div 的class名称]</span> </td>
            </tr>
            <tr>
                <td height="28" align="center" class="form_tdText">文件名 </td>
                <td class="form_tdText">&nbsp;<asp:TextBox ID="txtUrl" runat="server" Width="150"
                    Text="*.html"></asp:TextBox>&nbsp;<font color="red">*</font><span class="form_desc">
                        [生成静态页面的文件名]</span></td>
            </tr>
            <tr style="display: none;">
                <td height="28" align="center" class="form_tdText">最大显示 </td>
                <td class="form_tdText">&nbsp;<asp:TextBox ID="txtMaxSize" runat="server" Width="80"
                    Text="20000"></asp:TextBox>
                    <font color="red">*</font> </td>
            </tr>
            <tr>
                <td height="28" align="center" class="form_tdText">每页显示 </td>
                <td class="form_tdText">&nbsp;<asp:TextBox ID="txtPageSize" runat="server" Width="80"
                    Text="10"></asp:TextBox>
                    <font color="red">*</font> <span class="form_desc">[每页显示数目]</span></td>
            </tr>
            <tr>
                <td height="28" align="center" class="form_tdText">语言版本 </td>
                <td class="form_tdText">&nbsp;
                    <asp:DropDownList ID="ddlLanguage" runat="server">
                        <asp:ListItem Text="中文式分页" Value="cn"></asp:ListItem>
                        <asp:ListItem Text="英文式分页" Value="en"></asp:ListItem>
                    </asp:DropDownList>
                    <font color="red">*</font></td>
            </tr>
            <tr style="display: none;">
                <td height="28" align="center" class="form_tdText">页脚 </td>
                <td class="form_tdText">&nbsp;<asp:TextBox ID="txtFooter" runat="server" Width="80">10</asp:TextBox>
                    <font color="red">*</font> </td>
            </tr>
            <tr>
                <td height="28" align="center" class="form_tdText" colspan="2">
                    <input id="Button1" type="button" value="插入" class="btn_default" onclick="insertLabel();" />
                    <input id="Button2" type="button" value="编辑" class="btn_default" onclick="editLabel();" />
                </td>
            </tr>
        </table>
    </form>
</body>
</html>

<script language="javascript">
<!--
//编辑时初始化数据
function setEdit()
{
    var isEdit = (window.location.href.indexOf("?e")!=-1) ? true : false;
    if(isEdit)
    {
        document.getElementById("Button1").style.display = 'none';
        document.getElementById("Button2").style.display = '';
   
        var label = window.dialogArguments;    //标签
        
        var index1 = label.indexOf(">");
        var top = label.substring(0, index1+1);    //头部
        
        while(true)
        {
            var mc = top.match(new RegExp("[a-zA-Z]+[ ]*=[ ]*\"[^\"]*\""));    //取参数
            
            if(mc != null)
            {
                var k = mc[0].indexOf('=');
                var m1=mc[0].substring(0,k).toLowerCase(), m2=mc[0].substring(k+2,mc[0].length-1);
                
                switch(m1)
                {
                    case "id":
                        document.getElementById("txtID").value=m2;
                        break;
                    case "class":
                        document.getElementById("txtClass").value=m2;
                        break;
                    case "url":
                        document.getElementById("txtUrl").value=m2;
                        break;
                    case "maxsize":
                        document.getElementById("txtMaxSize").value=m2;
                        break;
                    case "pagesize":
                        document.getElementById("txtPageSize").value=m2;
                        break;
                    case "footer":
                        document.getElementById("txtFooter").value=m2;
                        break;
                    case "language":
                        {
                            var objSelect = document.getElementById("ddlLanguage");
                            for(var i=0;i<objSelect.options.length;i++)
                            {
                                if(objSelect.options[i].value == m2)
                                {
                                    objSelect.options[i].selected = true;
                                    break;
                                }
                            } 
                        }
                        break;
                    default:break;
                }
                
                top = top.replace(mc[0], "");    //逐个替换
            }
            else
                break;
        }
    }
    else
    {
        document.getElementById("Button1").style.display = '';
        document.getElementById("Button2").style.display = 'none';
    }
}

//保存
function insertLabel()
{
   if(!checkForm())
       return false;

    var MyArgs = window.dialogArguments;

    MyArgs[0] = MyArgs[0] + labelCreate();
    
    window.returnValue = MyArgs;
    window.close();
}

//修改
function editLabel()
{
    if(!checkForm())
       return false;
    
    window.returnValue = labelCreate();
    window.close();
}

function labelCreate()
{
    var Id = document.getElementById("txtID").value;
    var Class = document.getElementById("txtClass").value;
    var Url = document.getElementById("txtUrl").value;
    var MaxSize = document.getElementById("txtMaxSize").value;
    var PageSize = document.getElementById("txtPageSize").value;
    var Footer = document.getElementById("txtFooter").value;
    var Language = document.getElementById("ddlLanguage");
    Language =  Language.options[Language.selectedIndex].value;
    var label = "<Whir:Page";
    label += " ID=\""+Id+"\"";
    label += " Class=\""+Class+"\"";
    label += " Url=\""+Url+"\"";
    label += " MaxSize=\""+MaxSize+"\"";
    label += " PageSize=\""+PageSize+"\"";
    label += " Footer=\""+Footer+"\"";
    label += " Language=\""+Language+"\"";
    label += "></Whir:Page>";
    
    return label;
}

function checkForm()
{
    var txtID = document.getElementById("txtID");
    if(txtID.value.replace(/[ ]/g,'') == '')
    {
        alert("请输入ID!");
        txtID.focus();
        return false;
    }
    
    var txtUrl = document.getElementById("txtUrl");
    if(txtUrl.value.search(/^[a-zA-Z0-9_]+\.[a-zA-Z]+$/) == -1)
    {
        alert("请输入文件名[带后缀]!");
        txtUrl.focus();
        return false;
    }
    
    var txtMaxSize = document.getElementById("txtMaxSize");
    if(txtMaxSize.value.search(/^\d+$/) == -1)
    {
        alert("请输入最大显示[数字]!");
        txtMaxSize.focus();
        return false;
    }
    
    var txtPageSize = document.getElementById("txtPageSize");
    if(txtPageSize.value.search(/^\d+$/) == -1)
    {
        alert("请输入每页显示[数字]!");
        txtPageSize.focus();
        return false;
    }
    
    var txtFooter = document.getElementById("txtFooter");
    if(txtFooter.value.search(/^\d+$/) == -1)
    {
        alert("请输入页脚[数字]!");
        txtFooter.focus();
        return false;
    }
    
    return true;
}
//-->
</script>

<script language="javascript" src="../../Js/common.js"></script>

<script type="text/javascript">initAutoFormStyle();</script>

